﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Bot.Dynamics365.Model
{
    public class Attribute
    {
        public string odatatype { get; set; }
        public string MetadataId { get; set; }
        public object HasChanged { get; set; }
        public string AttributeOf { get; set; }
        public string AttributeType { get; set; }
        public int ColumnNumber { get; set; }
        public object DeprecatedVersion { get; set; }
        public string IntroducedVersion { get; set; }
        public string EntityLogicalName { get; set; }
        public bool IsCustomAttribute { get; set; }
        public bool IsPrimaryId { get; set; }
        public bool IsValidODataAttribute { get; set; }
        public bool IsPrimaryName { get; set; }
        public bool IsValidForCreate { get; set; }
        public bool IsValidForRead { get; set; }
        public bool IsValidForUpdate { get; set; }
        public bool CanBeSecuredForRead { get; set; }
        public bool CanBeSecuredForCreate { get; set; }
        public bool CanBeSecuredForUpdate { get; set; }
        public bool IsSecured { get; set; }
        public bool IsRetrievable { get; set; }
        public bool IsFilterable { get; set; }
        public bool IsSearchable { get; set; }
        public bool IsManaged { get; set; }
        public object LinkedAttributeId { get; set; }
        public string LogicalName { get; set; }
        public bool IsValidForForm { get; set; }
        public bool IsRequiredForForm { get; set; }
        public bool IsValidForGrid { get; set; }
        public string SchemaName { get; set; }
        public object ExternalName { get; set; }
        public bool IsLogical { get; set; }
        public bool IsDataSourceSecret { get; set; }
        public object InheritsFrom { get; set; }
        public DateTime CreatedOn { get; set; }
        public DateTime ModifiedOn { get; set; }
        public int? SourceType { get; set; }
        public string AutoNumberFormat { get; set; }
        public string Format { get; set; }
        public string ImeMode { get; set; }
        public int MaxLength { get; set; }
        public string YomiOf { get; set; }
        public bool IsLocalizable { get; set; }
        public int DatabaseLength { get; set; }
        public string FormulaDefinition { get; set; }
        public int SourceTypeMask { get; set; }
        public Attributetypename AttributeTypeName { get; set; }
        public Description Description { get; set; }
        public Displayname DisplayName { get; set; }
        public Isauditenabled IsAuditEnabled { get; set; }
        public Isglobalfilterenabled IsGlobalFilterEnabled { get; set; }
        public Issortableenabled IsSortableEnabled { get; set; }
        public Iscustomizable IsCustomizable { get; set; }
        public Isrenameable IsRenameable { get; set; }
        public Isvalidforadvancedfind IsValidForAdvancedFind { get; set; }
        public Requiredlevel RequiredLevel { get; set; }
        public Canmodifyadditionalsettings CanModifyAdditionalSettings { get; set; }
        public object[] Settings { get; set; }
        public Formatname FormatName { get; set; }
        public float MaxValue { get; set; }
        public float MinValue { get; set; }
        public int Precision { get; set; }
        public int PrecisionSource { get; set; }
        public string CalculationOf { get; set; }
        public bool IsBaseCurrency { get; set; }
        public int? DefaultFormValue { get; set; }
        public object ParentPicklistLogicalName { get; set; }
        public object[] ChildPicklistLogicalNames { get; set; }
        public string[] Targets { get; set; }
        public DateTime MinSupportedValue { get; set; }
        public DateTime MaxSupportedValue { get; set; }
        public Datetimebehavior DateTimeBehavior { get; set; }
        public Canchangedatetimebehavior CanChangeDateTimeBehavior { get; set; }
        public bool DefaultValue { get; set; }
        public bool IsEntityReferenceStored { get; set; }
        public bool IsPrimaryImage { get; set; }
        public int MaxHeight { get; set; }
        public int MaxWidth { get; set; }
        public int MaxSizeInKB { get; set; }
        public bool CanStoreFullImage { get; set; }

        public string Label
        {
            get
            {
                if (DisplayName != null
                    && DisplayName.LocalizedLabels != null
                    && DisplayName.LocalizedLabels.Length > 0)
                {
                    return DisplayName.LocalizedLabels[0].Label;
                }

                return LogicalName;
            }
        }

        public bool Required
        {
            get
            {
                if (IsRequiredForForm && LogicalName != "ownerid")
                {
                    return true;
                }

                return false;
            }
        }
    }
}
